package com.edu.boot.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.edu.boot.entity.Recruitment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.edu.boot.entity.Vo.BusinessShopAllInfoVo;
import com.edu.boot.entity.Vo.RecruitmentAllInfoVo;
import com.edu.boot.entity.Vo.ShopAndRecruitmentVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author 。
* @description 针对表【recruitment】的数据库操作Mapper
* @createDate 2023-11-16 13:53:20
* @Entity com.edu.boot.entity.Recruitment
*/
@Mapper
public interface RecruitmentMapper extends BaseMapper<Recruitment> {
    /**
     * 通过uid rid获取所有用户 商店 招聘信息
     * @param uid
     * @param bid
     * @return
     */
    @Select("SELECT * FROM `user` LEFT JOIN `business_shop` ON (${uid}=business_shop.uid) LEFT JOIN `recruitment` ON (${bid}=recruitment.b_id) WHERE user.uid=business_shop.uid AND business_shop.b_id=recruitment.b_id;")
    List<RecruitmentAllInfoVo> getRecruitmentAndInfoById(Integer uid,Integer bid);

    @Select("SELECT * FROM `business_shop` LEFT JOIN `recruitment` ON ${bid}=recruitment.b_id WHERE business_shop.b_id=recruitment.b_id;")
    List<ShopAndRecruitmentVo> getShopAndRecruitmentInfoByBid(Integer bid);

    /**
     * 通过商店bid 获取招聘信息
     * @param id
     * @return
     */
    @Select("select * form user where ${id} = uid")
    List<Recruitment> getRecruitmentById(Integer id);

    @Select("SELECT `user`.username,`user`.nickname, `user`.mobile, `user`.email, `user`.sh_status, `user`" +
            ".image_data, re.* FROM " +
            "recruitment AS re LEFT " +
            "JOIN `user` ON re.b_id = `user`.uid WHERE re.sh_status = 2 ORDER BY re.create_time DESC")
    List<RecruitmentAllInfoVo> getUserAllInfo();
    @Select("SELECT `user`.username,`user`.nickname, `user`.mobile, `user`.email, `user`.sh_status, `user`" +
            ".image_data, re.* FROM  " +
            "recruitment AS re LEFT JOIN `user` ON re.b_id = `user`.uid WHERE re.sh_status = 2 and re.rec_id=${rid}")
    RecruitmentAllInfoVo getUserAllShopRecruitmentInfoByRid(Integer rid);
    
    @Select("SELECT `user`.username, `user`.mobile, `user`.email, `user`.sh_status, `user`.image_data, re.* FROM " +
            "recruitment AS re LEFT " +
            "JOIN `user` ON re.b_id = `user`.uid WHERE re.sh_status = 2 and re.rec_name like concat('%', #{search}, " +
            "'%')  ORDER BY re.create_time " +
            "DESC")
    List<RecruitmentAllInfoVo> getUserAllInfoSearch(String search);
    
    IPage<RecruitmentAllInfoVo> getRecrutimeAdminList(Page<RecruitmentAllInfoVo> page, String recName, Integer recType);
}
